package com.coolgor.coldot.dao.stock;

import com.coolgor.coldot.entity.stock.StockFollower;
import org.apache.ibatis.annotations.*;
import java.util.List;


@Mapper
public interface StockFollowerDao {

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_stock_follower
			WHERE
				record_id = #{recordID}
		</script>
	""")
	@Results(id = "StockFollowerMap", value = {
		@Result(property = "recordID", column = "record_id"),
		@Result(property = "code", column = "code"),
		@Result(property = "name", column = "name"),
		@Result(property = "measure", column = "measure"),
		@Result(property = "quota", column = "quota"),
		@Result(property = "follower", column = "follower"),
		@Result(property = "context", column = "context"),
		@Result(property = "lastReportTime", column = "last_report_time"),
		@Result(property = "flag", column = "flag"),
		@Result(property = "createTime", column = "create_time"),
		@Result(property = "lastEditTime", column = "last_edit_time"),
		@Result(property = "remark", column = "remark")
	})
	StockFollower queryByID(@Param("recordID") Long recordID);

	@Select("""
		<script>
			SELECT
				*
			FROM
				tb_coldot_stock_follower
			<where>
				<if test="stockFollowerCondition.recordID != null">
					and record_id = #{stockFollowerCondition.recordID}
				</if>
				<if test="stockFollowerCondition.code != null">
					and code like '${stockFollowerCondition.code}'
				</if>
				<if test="stockFollowerCondition.name != null">
					and name like '${stockFollowerCondition.name}'
				</if>
				<if test="stockFollowerCondition.measure != null">
					and measure like '${stockFollowerCondition.measure}'
				</if>
				<if test="stockFollowerCondition.quota != null">
					and quota like '${stockFollowerCondition.quota}'
				</if>
				<if test="stockFollowerCondition.follower != null">
					and follower like '${stockFollowerCondition.follower}'
				</if>
				<if test="stockFollowerCondition.context != null">
					and context like '${stockFollowerCondition.context}'
				</if>
				<if test="stockFollowerCondition.lastReportTime != null">
					and last_report_time = #{stockFollowerCondition.lastReportTime}
				</if>
				<if test="stockFollowerCondition.lastReportTime != null">
					and <![CDATA[ last_report_time >= #{stockFollowerCondition.lastReportTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.lastReportTime != null">
					and <![CDATA[ last_report_time <= #{stockFollowerCondition.lastReportTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.flag != null">
					and flag = #{stockFollowerCondition.flag}
				</if>
				<if test="stockFollowerCondition.createTime != null">
					and create_time = #{stockFollowerCondition.createTime}
				</if>
				<if test="stockFollowerCondition.createTime != null">
					and <![CDATA[ create_time >= #{stockFollowerCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.createTime != null">
					and <![CDATA[ create_time <= #{stockFollowerCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.lastEditTime != null">
					and last_edit_time = #{stockFollowerCondition.lastEditTime}
				</if>
				<if test="stockFollowerCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time >= #{stockFollowerCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time <= #{stockFollowerCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.remark != null">
					and remark like '${stockFollowerCondition.remark}'
				</if>
			</where>
			LIMIT #{rowIndex},#{pageSize};
		</script>
	""")
	@ResultMap("StockFollowerMap")
	List<StockFollower> queryList(@Param("stockFollowerCondition") StockFollower stockFollowerCondition,
							@Param("rowIndex") int rowIndex,
							@Param("pageSize") int pageSize);

	@Select("""
		<script>
			SELECT
				count(1)
			FROM
				tb_coldot_stock_follower
			<where>
				<if test="stockFollowerCondition.recordID != null">
					and record_id = #{stockFollowerCondition.recordID}
				</if>
				<if test="stockFollowerCondition.code != null">
					and code like '${stockFollowerCondition.code}'
				</if>
				<if test="stockFollowerCondition.name != null">
					and name like '${stockFollowerCondition.name}'
				</if>
				<if test="stockFollowerCondition.measure != null">
					and measure like '${stockFollowerCondition.measure}'
				</if>
				<if test="stockFollowerCondition.quota != null">
					and quota like '${stockFollowerCondition.quota}'
				</if>
				<if test="stockFollowerCondition.follower != null">
					and follower like '${stockFollowerCondition.follower}'
				</if>
				<if test="stockFollowerCondition.context != null">
					and context like '${stockFollowerCondition.context}'
				</if>
				<if test="stockFollowerCondition.lastReportTime != null">
					and last_report_time = #{stockFollowerCondition.lastReportTime}
				</if>
				<if test="stockFollowerCondition.lastReportTime != null">
					and <![CDATA[ last_report_time >= #{stockFollowerCondition.lastReportTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.lastReportTime != null">
					and <![CDATA[ last_report_time <= #{stockFollowerCondition.lastReportTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.flag != null">
					and flag = #{stockFollowerCondition.flag}
				</if>
				<if test="stockFollowerCondition.createTime != null">
					and create_time = #{stockFollowerCondition.createTime}
				</if>
				<if test="stockFollowerCondition.createTime != null">
					and <![CDATA[ create_time >= #{stockFollowerCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.createTime != null">
					and <![CDATA[ create_time <= #{stockFollowerCondition.createTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.lastEditTime != null">
					and last_edit_time = #{stockFollowerCondition.lastEditTime}
				</if>
				<if test="stockFollowerCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time >= #{stockFollowerCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.lastEditTime != null">
					and <![CDATA[ last_edit_time <= #{stockFollowerCondition.lastEditTime,jdbcType=DATE} ]]>
				</if>
				<if test="stockFollowerCondition.remark != null">
					and remark like '${stockFollowerCondition.remark}'
				</if>
			</where>
		</script>
	""")
	int queryCount(@Param("stockFollowerCondition") StockFollower stockFollowerCondition);

	@Insert("""
		<script>
			INSERT INTO tb_coldot_stock_follower (
				code,
				name,
				measure,
				quota,
				follower,
				context,
				last_report_time,
				flag,
				create_time,
				last_edit_time,
				remark
			) VALUES (
				#{code},
				#{name},
				#{measure},
				#{quota},
				#{follower},
				#{context},
				#{lastReportTime},
				#{flag},
				#{createTime},
				#{lastEditTime},
				#{remark}
			)
		</script>
	""")
	@Options(useGeneratedKeys = true, keyColumn = "record_id", keyProperty = "recordID")
	int insert(StockFollower stockFollower);

	@Update("""
		<script>
			UPDATE tb_coldot_stock_follower
			<set>
				<if test="code != null">code=#{code},</if>
				<if test="name != null">name=#{name},</if>
				<if test="measure != null">measure=#{measure},</if>
				<if test="quota != null">quota=#{quota},</if>
				<if test="follower != null">follower=#{follower},</if>
				<if test="context != null">context=#{context},</if>
				<if test="lastReportTime != null">last_report_time=#{lastReportTime},</if>
				<if test="flag != null">flag=#{flag},</if>
				<if test="createTime != null">create_time=#{createTime},</if>
				<if test="lastEditTime != null">last_edit_time=#{lastEditTime},</if>
				<if test="remark != null">remark=#{remark}</if>
			</set>
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int update(StockFollower stockFollower);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_stock_follower
			WHERE
				record_id = #{recordID}
		</script>
	""")
	int delete(Long recordID);

	@Delete("""
		<script>
			DELETE FROM tb_coldot_stock_follower
			WHERE
				record_id IN
				<foreach collection="list" item="recordID" open="(" separator="," close=")">
					#{recordID}
				</foreach>
		</script>
	""")
	int deleteBatch(List<Long> idList);

}